home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / gamma-bros.swf / scripts / __Packages / classes / misc / WheelBot.as < prev   
Encoding:
Text File  |  2011-10-17  |  5.7 KB  |  244 lines

  1. class classes.misc.WheelBot
  2. {
  3.    var x;
  4.    var y;
  5.    var clip;
  6.    var dir;
  7.    var doorOpen;
  8.    var oldDir;
  9.    var c = 0;
  10.    var c2 = 0;
  11.    var cMax = 0;
  12.    var c2Max = 0;
  13.    var xMov = 0;
  14.    var xMovT = 0;
  15.    var xA = 0;
  16.    var yA = 0;
  17.    var f2 = "";
  18.    var comp1D = false;
  19.    var comp2D = false;
  20.    var Name = "wheelBot";
  21.    function WheelBot(px, py)
  22.    {
  23.       this.x = px;
  24.       this.y = py;
  25.       this.clip = _root.attachMovie("wheelBot","wheelBotClip",90020);
  26.       this.clip._x = this.x;
  27.       this.clip._y = this.y;
  28.       this.xMov = this.xMovT = 4;
  29.       this.dir = "R";
  30.       _root.introScreen.littleDoorBlack._visible = true;
  31.       _root.introOverlay.littleDoor.gotoAndPlay("open");
  32.    }
  33.    function wander()
  34.    {
  35.       if(random(200) > 197)
  36.       {
  37.          this.dir = this.dir != "L" ? "L" : "R";
  38.          this.xMovT = this.dir != "L" ? 4 : -4;
  39.       }
  40.       else if(random(200) > 197)
  41.       {
  42.          this.comp1();
  43.       }
  44.       else if(random(200) > 197)
  45.       {
  46.          this.comp2();
  47.       }
  48.       else if(this.comp1D && this.comp2D && random(200) > 190)
  49.       {
  50.          this.goHome();
  51.       }
  52.    }
  53.    function goHome()
  54.    {
  55.       if(this.x < 130)
  56.       {
  57.          this.dir = "R";
  58.          this.xMovT = 4;
  59.          this.f2 = "goingHomePoint";
  60.       }
  61.       else
  62.       {
  63.          this.dir = "L";
  64.          this.xMovT = -4;
  65.          this.f2 = "goingHome";
  66.       }
  67.    }
  68.    function goingHome()
  69.    {
  70.       if(this.x < 130 && !this.doorOpen)
  71.       {
  72.          _root.introOverlay.littleDoor._visible = true;
  73.          _root.introScreen.littleDoorBlack._visible = true;
  74.          _root.introOverlay.littleDoor.gotoAndPlay("open");
  75.          this.doorOpen = true;
  76.       }
  77.       if(this.x < 10)
  78.       {
  79.          _root.introOverlay.littleDoor.gotoAndPlay("close");
  80.          _root.intro.wheelBot = false;
  81.          _root.removeChar("wheelBot");
  82.       }
  83.    }
  84.    function goingHomePoint()
  85.    {
  86.       if(this.x > 150)
  87.       {
  88.          this.dir = "L";
  89.          this.xMovT = -4;
  90.          this.f2 = "goingHome";
  91.       }
  92.    }
  93.    function comp1()
  94.    {
  95.       this.comp1D = true;
  96.       if(Math.abs(402 - this.x) < 4)
  97.       {
  98.          this.workComp1();
  99.       }
  100.       else
  101.       {
  102.          this.dir = this.x >= 402 ? "L" : "R";
  103.          this.xMovT = this.dir != "L" ? 4 : -4;
  104.          this.f2 = "gotoComp1";
  105.       }
  106.    }
  107.    function gotoComp1()
  108.    {
  109.       if(Math.abs(402 - this.x) < 4)
  110.       {
  111.          this.workComp1();
  112.       }
  113.    }
  114.    function workComp1()
  115.    {
  116.       this.xMovT = 0;
  117.       this.clip.wheel.gotoAndStop("stop");
  118.       this.f2 = "workingComp1";
  119.       this.c2 = 0;
  120.       this.c2Max = _root.randRange(30,120);
  121.       _root.introScreen.wheelComp1.gotoAndPlay("go");
  122.       _root.introScreen.wheelComp1Screen.gotoAndPlay("go");
  123.       this.dir = "B";
  124.    }
  125.    function workingComp1()
  126.    {
  127.       this.c2 = this.c2 + 1;
  128.       if(this.c2 == this.c2Max)
  129.       {
  130.          _root.introScreen.wheelComp1.gotoAndStop("main");
  131.          this.dir = random(2) <= 0 ? "L" : "R";
  132.          this.xMovT = this.dir != "L" ? 4 : -4;
  133.          this.f2 = "wander";
  134.          this.clip.wheel.gotoAndPlay(1);
  135.       }
  136.    }
  137.    function comp2()
  138.    {
  139.       this.comp2D = true;
  140.       if(Math.abs(951 - this.x) < 4)
  141.       {
  142.          this.workComp2();
  143.       }
  144.       else
  145.       {
  146.          this.dir = this.x >= 951 ? "L" : "R";
  147.          this.xMovT = this.dir != "L" ? 4 : -4;
  148.          this.f2 = "gotoComp2";
  149.       }
  150.    }
  151.    function gotoComp2()
  152.    {
  153.       if(Math.abs(951 - this.x) < 4)
  154.       {
  155.          this.workComp2();
  156.       }
  157.    }
  158.    function workComp2()
  159.    {
  160.       this.xMovT = 0;
  161.       this.clip.wheel.gotoAndStop("stop");
  162.       this.f2 = "workingComp2";
  163.       this.c2 = 0;
  164.       this.c2Max = _root.randRange(30,120);
  165.       this.dir = "B";
  166.    }
  167.    function workingComp2()
  168.    {
  169.       this.c2 = this.c2 + 1;
  170.       if(this.c2 == this.c2Max)
  171.       {
  172.          this.dir = random(2) <= 0 ? "L" : "R";
  173.          this.xMovT = this.dir != "L" ? 4 : -4;
  174.          this.f2 = "wander";
  175.          this.clip.wheel.gotoAndPlay(1);
  176.       }
  177.    }
  178.    function main()
  179.    {
  180.       this.c = this.c + 1;
  181.       this[this.f2]();
  182.       if(this.c == 40)
  183.       {
  184.          this.f2 = "wander";
  185.          _root.introOverlay.littleDoor.gotoAndPlay("close");
  186.       }
  187.       if(this.c == 55)
  188.       {
  189.          _root.introScreen.littleDoorBlack._visible = false;
  190.          _root.introOverlay.littleDoor._visible = false;
  191.       }
  192.       if(this.oldDir != this.dir)
  193.       {
  194.          this.clip.gotoAndStop(this.dir);
  195.          if(this.oldDir == undefined || this.dir == "F")
  196.          {
  197.             this.clip.eyes.gotoAndStop(this.dir);
  198.          }
  199.          else if(this.oldDir == "B")
  200.          {
  201.             this.clip.eyes.gotoAndPlay("Bto" + this.dir);
  202.          }
  203.          else if(this.dir == "B")
  204.          {
  205.             this.clip.eyes.gotoAndPlay(this.oldDir + "toB");
  206.          }
  207.          else if(random(3) > 0)
  208.          {
  209.             if(this.dir == "R")
  210.             {
  211.                this.clip.eyes.gotoAndPlay("LtoR");
  212.             }
  213.             else
  214.             {
  215.                this.clip.eyes.gotoAndPlay("RtoL");
  216.             }
  217.          }
  218.          else
  219.          {
  220.             this.clip.eyes.gotoAndPlay("spin" + this.dir);
  221.          }
  222.       }
  223.       this.oldDir = this.dir;
  224.       if(this.xMovT < this.xMov)
  225.       {
  226.          this.xMov -= 0.5;
  227.       }
  228.       else if(this.xMovT > this.xMov)
  229.       {
  230.          this.xMov += 0.5;
  231.       }
  232.       else
  233.       {
  234.          this.xMov = this.xMovT;
  235.       }
  236.       if(random(100) > 98)
  237.       {
  238.          this.clip.eyes.clip.gotoAndPlay("blink");
  239.       }
  240.       this.x += this.xMov + this.xA;
  241.       this.clip._x = this.x;
  242.    }
  243. }
  244.